package com.kzw.oa.system.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.kzw.core.service.hibernate.DefaultEntityManager;
import com.kzw.oa.system.model.AppRole;

@Service
@Transactional
public class AppRoleService extends DefaultEntityManager<AppRole, Long> {

	@Transactional(readOnly = true)
	public Map<String, Set<String>> getSecurityDataSource() {

		Map<String, Set<String>> source = new HashMap<String, Set<String>>();
		List<AppRole> roleList = getAll();
		for (AppRole role : roleList) {
			TreeSet<String> urlSet = new TreeSet<String>();
			// 取得某个角色的所有URL,TODO
//			Iterator<AppFunction> functions = role.getFunctions().iterator();
//			while (functions.hasNext()) {
//				AppFunction fun = functions.next();
//				Iterator<FunUrl> urlIt = fun.getFunUrls().iterator();
//				while (urlIt.hasNext()) {
//					urlSet.add(urlIt.next().getUrlPath());
//				}
//			}

			source.put(role.getName(), urlSet);
		}

		return source;
	}
	
	/**
	 * 批量删除（不能放在Action中）
	 * */
	public void multiDel(String[] ids) {
		for (String id : ids) {
			AppRole appRole = get(new Long(id));
			remove(appRole);
		}
	}
}
